using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

namespace EditorExtensions
{

    public class PopUpWindowExample : EditorWindow
    {
        [MenuItem("EditorExtensions/09.PopUp/Open")]
        static void Open()
        {
            GetWindow<PopUpWindowExample>().Show();
        }

        private Rect mButtonRect;
        private void OnGUI()
        {
            if (GUILayout.Button("Popup Options", GUILayout.Width(200)))
            {
                PopupWindow.Show(mButtonRect, new PopupWindowContentExample());
            }

            if (Event.current.type == EventType.Repaint)
            {
                mButtonRect = GUILayoutUtility.GetLastRect();
            }
        }

        public class PopupWindowContentExample : PopupWindowContent
        {
            private bool mToggle1 = true;
            private bool mToggle2 = true;
            private bool mToggle3 = true;

            public override Vector2 GetWindowSize()
            {
                return new Vector2(200, 150);
            }

            public override void OnGUI(Rect rect)
            {
                GUILayout.Label("Popup Options Example", EditorStyles.boldLabel);
                mToggle1 = EditorGUILayout.Toggle("toggle1 ", mToggle1);
                mToggle2 = EditorGUILayout.Toggle("toggle2 ", mToggle2);
                mToggle3 = EditorGUILayout.Toggle("toggle3 ", mToggle3);
            }

            public override void OnOpen()
            {
                base.OnOpen();
                Debug.Log("Open");
            }

            public override void OnClose()
            {
                base.OnClose();
                Debug.Log("Close");
            }
        }
       
    }

}
